package com.googlecode.agscrum.model.validator;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.reflect.MethodSignature;

@Aspect
public class AspectValidator {
	@Before(value = "execution(@com.googlecode.agscrum.model.validator.annotation.Validate * *(..))")
	public void notNull(JoinPoint thisJoinPoint) {
		Object[] objects = thisJoinPoint.getArgs();
		MethodSignature methodSignature = (MethodSignature) thisJoinPoint
				.getSignature();
		String[] parameterNames = methodSignature.getParameterNames();
		for (int i = 0; i < objects.length; i++) {
			if (objects[i] == null) {
				throw new IllegalArgumentException(parameterNames[i]
						+ " is null.");
			}
		}
	}
}
